﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ZG_member;
using System.Net;
using System.Configuration;
using System.IO;
using ZG_member.DAL;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace ZG_member
{
    
    static class Program
    {   
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        
        public static void Main()
        {
            Application.EnableVisualStyles();
            
            Application.SetCompatibleTextRenderingDefault(false);
            //try
            //{
            //    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
            //    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            //    if (resp.StatusCode == HttpStatusCode.OK)
            //    {
            //        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["fuwuqi"]);
            //        try
            //        {
            //            conn.Open();
            //            conn.Close();
            //        }
            //        catch (Exception)
            //        {
            //            MainForm.xianshi = "1";
            //            string x = "0";
            //            StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
            //            sw.Flush();
            //            sw.Write(x);
            //            sw.Close();
            //            string sqls = ConfigurationManager.AppSettings["bendi"];
            //            ConfigurationManager.AppSettings["ConnectionString"] = sqls;
            //            ConfigurationManager.AppSettings["details"] = "0";
            //            SQLsynchronization sc = new SQLsynchronization(sqls);
            //            sc.addjifen();
            //            System.Windows.Forms.MessageBox.Show("由于无法连接的服务器！本次将使用本地数据库！");
            //            LoginForm form1 = new LoginForm();
            //            form1.ShowDialog();
            //            if (LoginForm.go == 1)
            //            {
            //                Application.Run(new MainForm());
            //            }
            //            return;
            //        }
                        

                    
                    


            //        string sql = ConfigurationManager.AppSettings["fuwuqi"];
            //        ConfigurationManager.AppSettings["ConnectionString"] = sql;
            //        ConfigurationManager.AppSettings["details"] = "1";

            //        StreamReader writer = new StreamReader(Application.StartupPath + "\\Sqlupdate.txt");
                    
            //        string a = writer.ReadLine();
            //        writer.Close();
            //        if (a=="0")
            //        {
            //            MessageBox.Show("由于您的电脑之前于服务器断开连接，所以本次使用将会同步数据库。请您耐心等待");
            //            //SQLsynchronization sc = new SQLsynchronization(ConfigurationManager.AppSettings["bendi"]);
            //            //List<string> tablename = sc.Gettablename();
            //            //for (int i = 0; i < tablename.Count; i++)
            //            //{
            //            //    sc.synchronization(tablename[i]);
            //            //}
            //            //sc.chazhi();
            //            //MessageBox.Show("上传完成！");

            //            string x = "1";
            //            StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
            //            sw.Flush();
            //            sw.Write(x);
            //            sw.Close();
            //            schedule sche = new schedule(a);
            //            sche.ShowDialog();

            //        }


            //        StreamReader writers = new StreamReader(Application.StartupPath + "\\Sqlupdate.txt");

            //        string aa = writers.ReadLine();
            //        writers.Close();
                    
                    

            //        if (aa=="1")
            //        {
            //            //string xiazaisql = ConfigurationManager.AppSettings["bendi"];
            //            //ConfigurationManager.AppSettings["ConnectionString"] = xiazaisql;

            //            //SQLsynchronization sc = new SQLsynchronization(ConfigurationManager.AppSettings["fuwuqi"]);
            //            //List<string> tablename = sc.Gettablename();
            //            //for (int i = 0; i < tablename.Count; i++)
            //            //{
            //            //    sc.synchronization(tablename[i]);
            //            //    //if (tablename[i]=="memberInfo")
            //            //    //{

            //            //    //}
            //            //}
            //            //MessageBox.Show("下载完成！");
            //            //string xiazaisqlOK = ConfigurationManager.AppSettings["fuwuqi"];
            //            //ConfigurationManager.AppSettings["ConnectionString"] = xiazaisqlOK;
            //            string x = "2";
            //            StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
            //            sw.Flush();
            //            sw.Write(x);
            //            sw.Close();
            //            schedule sche = new schedule(aa);
            //            sche.ShowDialog();
            //        }
            //        resp.Close();
            //    }
            //    else
            //    {
            //        System.Windows.Forms.MessageBox.Show("由于无法连接的服务器！本次将使用本地数据库！");
            //    }
            //}
            //catch (WebException webex)
            //{
            //    MainForm.xianshi = "1";
            //    string x = "0";
            //    StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
            //    sw.Flush();
            //    sw.Write(x);
            //    sw.Close();
            //    string sql = ConfigurationManager.AppSettings["bendi"];
            //    ConfigurationManager.AppSettings["ConnectionString"] = sql;
            //    ConfigurationManager.AppSettings["details"] = "0";
            //    SQLsynchronization sc = new SQLsynchronization(sql);
            //    sc.addjifen();
            //    System.Windows.Forms.MessageBox.Show("由于无法连接的服务器！本次将使用本地数据库！");

            //}



            LoginForm form = new LoginForm();
            form.ShowDialog();
            if (LoginForm.go == 1)
            {
                Application.Run(new MainForm());
            }

            //Application.Run(new User_ProductwaterForm());
        }
    }
}
